<template>
	<div class="allcontainer">
		<div class="h2">获奖记录管理（共{{ data.length }}条数据）</div>
		<a-button-group size="default" class="option" v-if="ChargeUserNo==UserInfo.UserNo && State!=5 && State!=4">
			<a-button type="primary" class="btn" @click="addList" >新增</a-button>
			<a-button type="primary" class="btn" @click="fileimport">导入</a-button>
		</a-button-group>
		<div class="">
			<el-table stripe :data="data" v-loading="loading" :max-height="tableHeight" highlight-current-row style="width: 100%;">
				<el-table-column type="index" label="序号" width="60"></el-table-column>
				<el-table-column prop="Name" label="获奖人" min-width="100">
					<template slot-scope="scope">
						{{ scope.row.UserName }} / {{ scope.row.UserNo }}
					</template>
				</el-table-column>
				<el-table-column prop="Score" label="分值" min-width="100">
					<template slot-scope="scope">
						<a-tag color="green">{{ scope.row.Score ? scope.row.Score : '暂无' }}</a-tag>
					</template>
				</el-table-column>
				<el-table-column prop="Score" label="奖项" min-width="100">
					<template slot-scope="scope">
						<a-tag color="green">{{ scope.row.ActivityTypePrizeTitle }}{{ scope.row.PrizeTitle?' | '+scope.row.PrizeTitle:'' }}</a-tag>
					</template>
				</el-table-column>
				<el-table-column label="操作" width="140">
					<template slot-scope="scope">
						<!-- <i title="修改" class="iconfont icon-editor1" style="color: #1890FF;" @click="modifyList(scope.row, 'modify')"></i> -->
						<i title="删除" v-if="ChargeUserNo==UserInfo.UserNo && State!=5 && State!=4" class="iconfont icon-delete" style="color: red;" @click="deleteList(scope.row)"></i>
						<!-- <i title="奖项管理" class="iconfont icon-delete" style="color: red;" @click="seeList(scope.row)"></i> -->
					</template>
				</el-table-column>
			</el-table>
		</div>
		<add :text="text" :userList="userList" :ActivityTypePrizeTypeList="ActivityTypePrizeTypeList" v-show="addIf" @closeFun="closeFun"></add>
		<exportcon :text="importText" :ActivityTypePrizeTypeList="ActivityTypePrizeTypeList" v-show="exportconIf" @closeFun="closeFun"></exportcon>
	</div>
</template>

<script>
import add from '@/components/addActivityMemberPrize.vue';
import Func from '@/utils/func';
import exportcon from '@/components/importActivityMemberPrize.vue';
import Cache from '@/utils/cache';
import { UserGetListActivityMemberPrize,CommonDoGetActivityTypePrizeTypeList, UserDoDeleteActivityMemberPrize,GetUserActivityMember,GetActivityTypePrizeListCommon,UserActivityDetail } from '@/api/follow';
const data = [];
export default {
	components: {
		add,
		exportcon
	},
	data() {
		return {
			data,
			form: this.$form.createForm(this, {
				name: 'advanced_search'
			}),
			pagination: {
				currentPage: 1,
				pageSize: this.global.pageSize,
				pageSizeOptions: this.global.pageSizeOptions, // 每页中显示的数据
				showTotal: total => `共有 ${total} 条数据` // 分页中显示总的数据
			},
			addIf: false,
			text: {},
			visible: false,
			confirmLoading: false,
			itemId: '',
			departmentList: [],
			worklist: [],
			loading: false,
			values: {},
			userList:[],
			ActivityTypePrizeList:[],
			tableHeight: parseFloat(window.innerHeight - 160),
			exportconIf:false,
			importText:{},
			ActivityTypePrizeTypeList:[],
			ChargeUserNo:'',
			UserInfo: Cache.get('myInfo'),
			State:0
		};
	},
	computed: {},
	created() {
		this.getList();
		this.getOtherList()
	},
	mounted() {},
	methods: {
		fileimport(){
			this.importText = { name:'奖项导入-用户',myType:'user',time:new Date }
			this.exportconIf = true
		},
		async getOtherList(){
			let detailRes = await UserActivityDetail({id:this.$route.query.activityID})
			this.ChargeUserNo = detailRes.data.data.ChargeUserNo
			this.State = detailRes.data.data.State
			let res2 = await CommonDoGetActivityTypePrizeTypeList()
			this.ActivityTypePrizeTypeList = res2.data.data
			let activityID = this.$route.query.activityID
			if(activityID){
				let res = await GetUserActivityMember({activityID:this.$route.query.activityID})
				this.userList = res.data.data
			}else{
				this.userList = [
					{
						ID:this.$route.query.activityMemberID,
						Name:this.$route.query.Name
					}
				]
			}
			// let res1 = await GetActivityTypePrizeListCommon({activityTypeID:this.$route.query.TypeID})
			// this.ActivityTypePrizeList = res1.data.data
		},
		handleSearch(e) {
			e.preventDefault();
			this.form.validateFields((error, values) => {
				this.pagination.currentPage = 1;
				this.values = values;
				this.getList();
			});
		},
		handleReset() {
			this.form.resetFields();
			this.values = {};
			this.getList();
		},
		handleSizeChange(val) {
			this.pagination.pageSize = val;
			this.getList();
		},
		handleCurrentChange(val) {
			this.pagination.currentPage = val;
			this.getList();
		},
		async getList() {
			this.loading = true;
			let data = {};
			if (this.values) {
				data = this.values;
			}
			data.activityID = this.$route.query.activityID
			data.activityMemberID = this.$route.query.activityMemberID
			let res = await UserGetListActivityMemberPrize(data);
			this.loading = false;
			this.data = res.data.data;
		},
		addList() {
			this.text = {myType:'user'};
			this.addIf = !this.addIf;
		},
		modifyList(text) {
			text = { ...text,time: new Date() }
			this.addIf = !this.addIf;
			this.text = text;
		},
		deleteList(text) {
			let that = this;
			this.$confirm({
				title: '提示',
				content: `您确定删除该类型吗？`,
				okText: '确认',
				cancelText: '取消',
				async onOk() {
					let data = {};
					data.id = text.ID;
					let res = await UserDoDeleteActivityMemberPrize(data);
					if (res.data.code == 0) {
						that.getList();
						that.$message.success(res.data.msg);
					} else {
						that.$message.error(res.data.msg);
					}
				}
			});
		},
		seeList(item) {
		},
		setFlow(text) {
			let path = '';
			path = 'ApplyActivityFlow';
			this.$router.push({
				name: path,
				query: {
					clubTypeID: text.ID
				}
			});
		},
		handleCancel(e) {
			this.visible = false;
		},
		closeFun(data) {
			this.addIf = false;
			this.exportconIf = false
			if(data==1){
				this.getList();
			}
		}
	}
};
</script>

<style lang="less" scoped>
.home-form {
		margin:20px;
		background: #F8FCFF;
		padding:20px;
		border-radius: 12px;
		.ant-col{
			width:19%;
			margin-right:1%;
			&.option{
				margin-top:25px;
				.ant-btn{
					padding:0 6px;
				}
			}
			/deep/.ant-form-item {
				margin-bottom: 10px !important;
			}
			/deep/.ant-form-item-label {
				height:20px;
				line-height:20px;
				font-weight: 400;
				color: #8798AD;
			}
			/deep/.ant-input{
				height: 32px;
				background: #FFFFFF;
				border: 1px solid #DDDEE4;
				border-radius:0px;
			}
			/deep/.ant-select-selection{
				height: 32px;
				background: #FFFFFF;
				border: 1px solid #DDDEE4;
				border-radius:0px;
			}
		}
	}
</style>
